package com.mama100.rpc.mdp.service.finagle;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.mama100.common.finagle.util.FinagleRPC;
import com.mama100.common.finagle.util.RpcUtil;
import com.mama100.rpc.mdp.MdpInoutUtil;
import com.mama100.rpc.mdp.constant.ResponseCode;
import com.mama100.rpc.mdp.thrift.inout.GetCustPointBatchRequest;
import com.mama100.rpc.mdp.thrift.inout.GetCustPointBatchResponse;
import com.mama100.rpc.mdp.thrift.inout.common.BaseResponse;
import com.twitter.util.ExecutorServiceFuturePool;
import com.twitter.util.Function0;
import com.twitter.util.Future;

@FinagleRPC
@Service
public class RpcCustPointService implements com.mama100.rpc.mdp.thrift.CustPointService.ServiceIface {

	protected Logger log = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private ExecutorServiceFuturePool futurePool;

	@Resource(name = "cpmsJdbcTemplate")
	JdbcTemplate jdbcTemplate;

	@Override
	public Future<GetCustPointBatchResponse> getCustPointBatch(GetCustPointBatchRequest req) {
		return futurePool.apply(new Function0<GetCustPointBatchResponse>() {
			@Override
			public GetCustPointBatchResponse apply() {

				GetCustPointBatchResponse resp = MdpInoutUtil.getGetCustPointBatchResponse(RpcUtil.genSeqNo());
				BaseResponse base = resp.getBaseResp();
				if (req.getBaseReq().getSeqNo() != null) {
					base.setSeqNo(req.getBaseReq().getSeqNo());
				}
				log.info("receive:" + req.toString());
				try {

				} catch (Exception e) {
					log.error("error:", e);
					base.setRespCode(ResponseCode.SERVER_ERROR.getCode());
					base.setRespDesc(ResponseCode.SERVER_ERROR.getDesc());
					log.info("return:" + resp);
					return resp;
				}
				base.setRespCode(ResponseCode.SUCCESS.getCode());
				base.setRespDesc(ResponseCode.SUCCESS.getDesc());
				log.info("return:" + resp.toString());
				return resp;
			}

		});
	}

}
